package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.AliyunOSSOperator;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Slf4j
@Api(tags = "通用接口")
@RequestMapping("/admin/common")
public class CommonController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /**
     * 文件上传 aliyun oss
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("file:{}", file.getOriginalFilename());
        //获取文件名
        String filename = file.getOriginalFilename();


        //将文件交给oss管理
        String url = aliyunOSSOperator.upload(file.getBytes(), filename);
        log.info("url:{}", url);
        //返回成功结果
        return Result.success(url);
    }

}
